﻿// Open Source: MIT License (http://www.opensource.org/licenses/mit-license.php)
// Project: YoProgramo.NET (http://code.google.com/p/yoprogramo/)
// Autor: Fabian Figueredo (info@fabianfigueredo.com.ar)
// Blog: blog.yoprogramo.net

using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Xml;
using YoProgramo.Infrastructure.Tools.Configuration;

namespace YoProgramo.Infrastructure.Tools.Handlers
{
    public class YoProgramoConfigurationHandler : IConfigurationSectionHandler {
        #region IConfigurationSectionHandler Members

        public object Create(object parent, object configContext, System.Xml.XmlNode section) {
            YoProgramoConfiguration yp = new YoProgramoConfiguration();
            yp.SiteName = section.Attributes["SiteName"].Value;
            yp.EmailAdmin = section.Attributes["EmailAdmin"].Value;
            yp.IsSiteLocked = Convert.ToBoolean(section.Attributes["IsSiteLocked"].Value);
            yp.IsRegistrationLocked = Convert.ToBoolean(section.Attributes["IsRegistrationLocked"].Value);

            IList<string> h = new List<string>();
            if (!string.IsNullOrEmpty(section.Attributes["EnableHostsWhenClose"].Value))
            {
                string[] hosts = section.Attributes["EnableHostsWhenClose"].Value.Split(new char[] { ',' });
                foreach(string s in hosts)
                {
                    h.Add(s.Trim());
                }
            }

            yp.EnableHostsWhenClose = h;

            return yp;
        }

        #endregion
    }
}